package club.sanmubird.travel_culture_wx_demo.biz.source.audio.controller;

import club.sanmubird.travel_culture_wx_demo.biz.source.audio.entity.Audio;
import club.sanmubird.travel_culture_wx_demo.biz.source.audio.sedrvice.AudioService;
import io.github.biezhi.anima.core.ResultKey;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

import static utils.BeanUtils.map2Bean;

/**
 * @program: travel_culture_wx_demo
 * @description: audioController
 * @author: sam
 * @create: 2018-08-05 21:20
 * @update: 2018-08-05 21:20
 * @update: Sam
 **/
@RestController
@RequestMapping("/audio")
public class AudioController {

	@Autowired
	private AudioService audioService;

	@RequestMapping("/{spotId}")
	public List<Audio> getAudioScenicSpotSid(@PathVariable Long spotId){
		return audioService.getAudiosBySpotId(spotId);
	}

	@RequestMapping("/save")
	public ResultKey save(@RequestBody Map map){
		Audio audio = map2Bean(map, Audio.class);
		return audioService.save(audio);
	}

	@RequestMapping("/batchSave")
	public void batchSave(@RequestParam(required = true) List<Audio> audioList){
		audioService.batchSave(audioList);
	}

	@RequestMapping("/update")
	public Integer update(@RequestBody Map map){
		Audio audio = map2Bean(map, Audio.class);
		return audioService.update(audio);
	}

	@RequestMapping("/delete/{audioSid}")
	public Integer deleteByAudioSid(@PathVariable Long audioSid){
		return audioService.deleteByAudioSid(audioSid);
	}

	/**
	 * 更改上架状态
	 * @param audioSid
	 * @return
	 */
	@RequestMapping("/updateStatus/{audioSid}/{status}")
	public Integer updateStatus(@PathVariable Long audioSid,@PathVariable Boolean status){
		return audioService.updateStatus(audioSid,status);
	}

}
